<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="util.Configuration"%>
<%@page import="persistence.DrupalHibernateManager"%>
<%@page import="util.Utils"%>
<%@page import="java.util.List"%>
<%@page import="domain.RepresentationsNamesRecord"%>
<%@page import="persistence.Axdbv4HibernateManager"%>

<%@page import="java.util.Date"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<%  
//	request.setCharacterEncoding("UTF-8");
	//System.out.println("DBSettings"+request.getSession().getAttribute("DBSettings"));
	String filterNames=null;
	String orderedBy=null;
	
	if(request.getParameter("orderedBy")!=null){
		orderedBy=request.getParameter("orderedBy");
		request.getSession().setAttribute("orderedBySetted", orderedBy);
	}else{
		if(request.getSession().getAttribute("orderedBySetted")!=null)
			orderedBy= (String) request.getSession().getAttribute("orderedBySetted");
		else orderedBy="alphabetical"; 
		
	}
	
	if(request.getParameter("nameFilter")!=null){ 
		filterNames=request.getParameter("nameFilter");
		request.getSession().setAttribute("filterNamesSetted", filterNames);
		
	}else{
		if(request.getSession().getAttribute("filterNamesSetted")!=null)
			filterNames=(String)request.getSession().getAttribute("filterNamesSetted");
		else filterNames= Configuration.filter_None;
	}
	int numberOfPage = 1;
	if(request.getParameter("page")!=null) numberOfPage = Integer.parseInt(request.getParameter("page"));
	String index = request.getParameter("index");

	String p = request.getParameter(String.copyValueOf(Utils.pRNumbers));
	if(request.getSession().getAttribute("DBSettings")==null){
		
		
		if(Configuration.getIstance().isReadDBConfigFileFailed()){
			//System.out.println("ATTENZIONE!File di configurazione del DataBase NON TROVATO!Verranno usati parametri standard: host="+Axdbv4HibernateManager.getHost()+" user="+Axdbv4HibernateManager.getUser()+"\n");
			//l'errore viene fatto stampare da Configuration
			
		}else{
			String[] settings= new String[3];
			settings[0]=Configuration.getIstance().getAxdbHost();
			settings[1]=Configuration.getIstance().getAxdbUser();
			settings[2]=Configuration.getIstance().getAxdbPassword();
		//	System.out.println("File di configurazione del DataBase trovato!Verranno usati i seguenti parametri letti da configurazione: host="+settings[0]+" user="+settings[1]+" pass="+settings[2]+"\n");
			Axdbv4HibernateManager.setHost(settings[0]);
			Axdbv4HibernateManager.setUser(settings[1]);
			Axdbv4HibernateManager.setPassword(settings[2]);
			DrupalHibernateManager.setHost(settings[0]);
			DrupalHibernateManager.setUser(settings[1]);
			DrupalHibernateManager.setPassword(settings[2]);
			request.getSession().setAttribute("DBSettings", settings);
		}
	}
	System.out.println("Avviata jsp(servlet) index.jsp (db access host:"+Axdbv4HibernateManager.getHost()+" user:"+Axdbv4HibernateManager.getUser()+" )");
	System.out.println("\tIndex:"+index+ " Page:"+numberOfPage+" Filtraggio:"+filterNames+" Ordered-by:"+orderedBy);
%>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="themes/js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="themes/js/jquery-ui.js" type="text/javascript"></script>
<script src="themes/js/jquery.highlight.js"></script>
<script type="text/javascript" src="themes/notify/jquery.pnotify.js"></script>
<!-- <script type="text/javascript" src="themes/notify/jquery.pnotify.min.js"></script> -->
<style type="text/css" >@import url("themes/notify/jquery.pnotify.default.css"); </style>
<!-- Include this file if you are using Pines Icons. -->
<link href="themes/notify/icon/jquery.pnotify.default.icons.css" media="all" rel="stylesheet" type="text/css" />

<style type="text/css" >@import url("themes/css/Stili.css"); </style>

<title>Names Management</title>

</head>
<body>
<div id="page" class="page">
	<div id="header" class="header" >
<!--  	<img  src='images/loading.gif' alt='...loading...'>-->
	 <div class="logoSynonyms">
		<div  <%=orderedBy.equals("frequency")?"class=\"Web_OnlineTools_Logo_Red\"":"class=\"Web_OnlineTools_Logo_Classic\""%>>

		<h1 id="header1_logo">Synonyms</h1>
		<div class="loadingGeneralPage" id="loadingGeneralPage">
			<img alt="...loading..." src="images/loading.gif">
		</div>
		</div>
	 </div>
	<div class="newnamebox" title="Type a name then press Enter to insert a new name">
			<input type="text" id="new-name-input" name="new-nameValue" value="Enter here a new name" onkeypress="newNameInserted(event)" onfocus="blackInput(this)" onblur='fillInput(this,"Enter here a new name")' >
	</div>

	<script type="text/javascript" src="themes/js/funzioniJavascript.js"></script>
	<script type="text/javascript"> <% if(p!=null){%>eg=1; egp="<%=p%>"<%} %></script> 
	
		<%	String ixPiccolo="&#10007;";
			String ixGrande="&#10008;";
			Date data = new Date();
			
		%>
		<div class="allLecterAndPageIndexes">
		<div class="lectersListForIndex">
		<%
			Axdbv4HibernateManager dbManager = Axdbv4HibernateManager.getIstance();
			
			char indice = 'a';
			boolean trovatoCharGiusto=false;
			for (int i = 0; i < 26; i++) {
				char a = (char) (i + 97);
				trovatoCharGiusto=false;
				if(index != null){ //controlla che non sto cercando i blackListed (sennò fa casino con la maiuscola)
				if ( (index.charAt(0) == a || index.charAt(0) == a - 97 + 65)
						&& index.length() == 1) {
					a = (char) (i + 65);
					indice = a;
					trovatoCharGiusto=true;
				}else{
					if(index.equals("*"))
					indice='*';}}
				
		%>
		<a onclick="clickCambiaUrl()" href="?index=<%=a%>" <%=trovatoCharGiusto?"class=\"lecterSelected\"":"" %>><%=a%></a>&nbsp;
		
		<%
			}
			int realMaxNumberOfPages=dbManager.getNumberOfPages(indice, filterNames,orderedBy.equals("frequency")?true:false);
			if(numberOfPage<1) numberOfPage=1;
			if(numberOfPage>realMaxNumberOfPages) numberOfPage=realMaxNumberOfPages;
		%>
		<a onclick="clickCambiaUrl()" href="?index=*"><%=indice=='*'?ixGrande:ixPiccolo %></a>
		</div>
		
		<div class="pagesListForIndex">
		'<%=indice%>' Pages: 
			<%for(int k=1;k<=realMaxNumberOfPages;k++){ %>
				<a onclick="clickCambiaUrl()" href="?index=<%=indice%>&page=<%=k%>" <%=k==numberOfPage?"class=\"pageSelected\"":"" %> ><%=k%></a>&nbsp;
			<% } %>
		</div>
		</div>
		
		<div id="statisticsDIV" class="statistics" >
			<a  href="statistics.jsp" target="_blank">Statistiche</a> <br>
			<a  href="settings" target="_blank">Settings</a>
		</div>
		<div class="filtraggioSuiNomiBox" title="Select the type of filter for the names retrieval.">
		  <div class="OneRowFilter">
			<div class="filterCouple">
				<input type="radio" name="nameFilter" id="AllFilter" onClick='jQuery("#loadingGeneralPage").css("display", "inline"); window.location.href ="?index=<%=indice%>&page=<%=numberOfPage%>&nameFilter=<%=Configuration.filter_None%>"' <%=filterNames.equals(Configuration.filter_None)?"checked":"" %>> <label for="AllFilter">All</label>
			</div>	
			<div class="filterCouple">
				<input type="radio" name="nameFilter" id="DBpediaFilter" onClick='jQuery("#loadingGeneralPage").css("display", "inline"); window.location.href ="?index=<%=indice%>&page=<%=numberOfPage%>&nameFilter=<%=Configuration.filter_DBpedia%>"'  <%=filterNames.equals(Configuration.filter_DBpedia)?"checked":"" %>> <label for="DBpediaFilter">Dbpedia</label>
			</div>
		 </div>
		 <div class="OneRowFilter">
			<div class="filterCouple">	
				<input type="radio" name="nameFilter" id="EclapUserFilter" onClick='jQuery("#loadingGeneralPage").css("display", "inline"); window.location.href ="?index=<%=indice%>&page=<%=numberOfPage%>&nameFilter=<%=Configuration.filter_EclapUser%>"'  <%=filterNames.equals(Configuration.filter_EclapUser)?"checked":"" %>> <label for="EclapUserFilter">EclapU</label>
			</div>	
			<div class="filterCouple">
				<input type="radio" name="nameFilter" id="BothFilter" onClick='jQuery("#loadingGeneralPage").css("display", "inline"); window.location.href ="?index=<%=indice%>&page=<%=numberOfPage%>&nameFilter=<%=Configuration.filter_DBpedia_AND_EclapUser%>"'  <%=filterNames.equals(Configuration.filter_DBpedia_AND_EclapUser)?"checked":"" %> > <label for="BothFilter">Both</label>
			</div>
			</div>
		
			<script>
$(document).ready(function() {
	
    $('.bool-slider .inset .control').click(function() {
        if (!$(this).parent().parent().hasClass('disabled')) {
            if ($(this).parent().parent().hasClass('true')) {
                $(this).parent().parent().addClass('false').removeClass('true');
               // alert("era true diventa false");
               jQuery("#loadingGeneralPage").css("display", "inline");
                window.location.href ="?index=<%=indice%>&page=<%=numberOfPage%>&nameFilter=<%=filterNames%>&orderedBy=frequency";
            } else {
                $(this).parent().parent().addClass('true').removeClass('false');
               // alert("era false diventa true");
               jQuery("#loadingGeneralPage").css("display", "inline");
                window.location.href ="?index=<%=indice%>&page=<%=numberOfPage%>&nameFilter=<%=filterNames%>&orderedBy=alphabetical";
            	
            }
        }
    });
});
</script>	<div class="OneRowFilter">
			<div class="modeOfWork">
			<div class="bool-slider <%=orderedBy.equals("frequency")?"false":"true"%>" title="Select the mode of names retrieval: &#10;-Normal: all names in alphabetical order; &#10;-Occurences: all occurring names in order of number of occurrences."> <!-- class="bool-slider true" -->
   				 <div class="inset">
        				<div class="control"></div>
   				 </div>
			</div>
			</div>
			</div>
		</div>
	</div>
	<script>indexWhereWeAre="<%=indice%>"</script>
	<div id="sx" class="containerLeft">
		
		<table border="1" id="elencoNomi">
			<tr>
				<th>Name</th>
				<th>Master</th>
				<th>Sinonimo</th>
				<th>isBlackListed</th>
			</tr>
			
			<%
				
				for (RepresentationsNamesRecord master : dbManager
						.getRepresentationNameListByFirstCharacter(indice,numberOfPage,filterNames,orderedBy.equals("frequency"))) { //,numberOfPage
					
			%><tr id="<%=master.getValue()%>" >
				<td <%=dbManager.hasEclapOrDBpediaAssociations(master.getNID())?"class=\"tdconassociazioni\"":"class=\"tdsenzaassociazioni\""%> onclick="nameClicked(&#34;<%=master.getValue()%>&#34;,&#34;<%=master.getNID() %>&#34;)" align="left" id="<%=master.getValue()%>" title="<%=master.getNID() %>"><b><%=master.getValue()%></b></td> <%-- <b><%=new String(master.getValue().getBytes(), "UTF-8")%></b></td> --%>
				<td align="center"><input type="radio" name="<%=master.getValue()%>"
					checked></td>
				<td align="center"></td>
				<td align="center"><input type="checkbox" name="<%=master.getValue()%>"
					<%=master.getIsBlackListed() ? "checked" : ""%> onclick="blackListChecked(&#34;<%=master.getValue()%>&#34;,&#34;<%=master.getValue()%>&#34;,this)"/></td>
			</tr>
			<%
				for (RepresentationsNamesRecord sinonimo : dbManager
							.getSynonymous(master)) {
			%>
			<tr id="<%=sinonimo.getValue()%>" >
				<td <%=dbManager.hasEclapOrDBpediaAssociations(sinonimo.getNID())?"class=\"tdconassociazioni\"":"class=\"tdsenzaassociazioni\""%>onclick="printExtraInfo(&#34;<%=sinonimo.getValue()%>&#34;,&#34;<%=sinonimo.getNID() %>&#34;)" align="right" id="<%=sinonimo.getValue()%>" title="<%=sinonimo.getNID()%>" ><%=sinonimo.getValue()%></td>
				<td align="center"><input type="radio" name="<%=master.getValue()%>" onclick="radioBoxSinonimoChecked(&#34;<%=sinonimo.getValue()%>&#34;,&#34;<%=master.getValue()%>&#34;,this)"></td>
				<td align="center"><input type="checkbox" name="<%=master.getValue()%>"
					checked onclick="checkBoxSinonimoClicked(&#34;<%=sinonimo.getValue()%>&#34;,&#34;<%=master.getValue()%>&#34;,this)"/></td>
				<td align="center"><input type="checkbox" name="<%=master.getValue()%>"
					<%=sinonimo.getIsBlackListed() ? "checked" : ""%> onclick="blackListChecked(&#34;<%=sinonimo.getValue()%>&#34;,&#34;<%=master.getValue()%>&#34;,this)"/></td>
			</tr>
			<%
				}
	
				}
			%>
	 
       
    
		</table>
		
	</div>
	
	
	<div id="dx" class="containerRight">
		 <div class="bigdown"> <!-- ANDRA' SOTTO!!! -->
		 	<div id="titoloExtraInfo" class="nomeSinonimoExtraInfo"></div>
		 	<div class="ricercheExtraInfo" title="-A RED sticker means not searched &#10;-A GREEN sticker means searched" >
		 		<div id="ExtraInfoDBpediaSearch" class="ExtraInfoDBpediaNotSearched">
					DBpedia
				</div >
				<div id="ExtraInfoEclapSearch" class="ExtraInfoEclapNotSearched">
					Eclap
				</div>
			 </div>
			 <div id="userordpbediainfoDIV" class="down">
          		  <span class="ExtraInformations" id="idExtraInfo" title="idExtraInfo">
          		  Click a name in the table to start the engine!
          		  
          		  </span>
      		  </div>
		</div>
		
		<div id="nome" class="bigup"> <!-- ANDRA' SOPRA!!!! -->
			<div id="nomeSinonimo" class="nomeSinonimoExtraInfo"> 
				
			</div>
			</div>
			<div id="occorrenzeDIV" class="up"> 
			Click a name in the table to start the engine!  
			</div>

		</div>
	

</div>


</body>
</html>
<!-- (&#8224;&#9724;&#9751;&#9775;&#9762;&#9760;&#9763;&#9746;&#9747;&#9752;&#9824;&#9787;&#9842;&#9843;&#9844;&#9845;&#9846;&#9847;&#9848;&#9849;&#9850;&#9851;&#9852;&#9853;&#9873;&#9985;&#9986;&#9987;&#9988;&#8864;&#9832;&#9729;&#9635;&#9425;&#9399;&#9409;&#9166;&#9167;&#10005;&#10006;&#10007;&#10008;&#10009;&#10010;&#10011;&#10012;&#10013;&#10014;&#10015;&#10016;&#10017;&#5718;&#5719;&#5720;&#8689;&#8690;&#8682;&#8998;&#8999;&#8984;&#10086;&#9785;&#12304;&#12305;&#55296;&#57096;)

<br>
&#12304;&#9425;&#9409;&#12305;
<br>
&#12304;BL&#12305;
<br>
&#8224;&#9760;&#8224;
<br>
&#9729;&#9763;&#9729; -->